package com.earth.amazeadmin.config.mybatis.utils;

import org.springframework.core.env.Environment;

import java.util.Properties;

/**
 * Created by dongjigong on 2018/5/3.
 *
 * @Email osbornjonny@126.com
 * @Description
 */
public class CommonUtils {

    public static Properties build(Environment env, String prefix, String dataSourceName) {

        Properties prop = new Properties();
        prop.put("url", env.getProperty(prefix + dataSourceName + "url"));
        prop.put("username", env.getProperty(prefix + dataSourceName + "username"));
        prop.put("password", env.getProperty(prefix + dataSourceName + "password"));
        prop.put("driverClassName", env.getProperty(prefix + dataSourceName + "driver-class-name", ""));
        prop.put("initialSize", env.getProperty(prefix + "initial-size", Integer.class));
        prop.put("maxActive", env.getProperty(prefix + "max-active", Integer.class));
        prop.put("minIdle", env.getProperty(prefix + "min-idle", Integer.class));
        prop.put("maxWait", env.getProperty(prefix + "max-wait", Integer.class));
        prop.put("poolPreparedStatements", env.getProperty(prefix + "pool-prepared-statements", Boolean.class));

        prop.put("maxPoolPreparedStatementPerConnectionSize",
                env.getProperty(prefix + "max-pool-prepared-statement-per-connection-size", Integer.class));

        prop.put("validationQuery", env.getProperty(prefix + "validation-query"));
        prop.put("validationQueryTimeout", env.getProperty(prefix + "validation-query-timeout", Integer.class));
        prop.put("testOnBorrow", env.getProperty(prefix + "test-on-borrow", Boolean.class));
        prop.put("testOnReturn", env.getProperty(prefix + "test-on-return", Boolean.class));
        prop.put("testWhileIdle", env.getProperty(prefix + "test-while-idle", Boolean.class));
        prop.put("timeBetweenEvictionRunsMillis",
                env.getProperty(prefix + "time-between-eviction-runs-millis", Integer.class));
        prop.put("minEvictableIdleTimeMillis", env.getProperty(prefix + "min-evictable-idle-time-millis", Integer.class));
        prop.put("filters", env.getProperty(prefix + "filters"));

        return prop;
    }
}
